<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员页面</title>
    <script src="../../js/vue.js"></script>
    <script src="../../element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="../../element-ui/lib/theme-chalk/index.css">
    <script src="../../js/axios-0.18.0.js"></script>
    <style>
        .el-header, .el-footer {
            background-color: #545C60;
            color: #333;
            text-align: center;
            line-height: 60px;
        }

        .el-aside {
            background-color: #545C80;
            color: #333;
            text-align: center;
            line-height: 200px;
        }

        .el-main {
            background-color: #E9EEF3;
            color: #333;
            text-align: center;
            line-height: 10px;
        }

        body > .el-container {
            margin-bottom: 40px;
        }

        .el-container:nth-child(5) .el-aside,
        .el-container:nth-child(6) .el-aside {
            line-height: 260px;
        }

        .el-container:nth-child(7) .el-aside {
            line-height: 320px;
        }
    </style>
    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>
<div id="app">

    <!--添加数据对话框表单-->
    <el-dialog
            title="编辑信息"
            :visible.sync="dialogVisible"
            width="30%">
        <el-form ref="form" :model="peInfo" label-width="75px">
            <el-form-item label="姓名:">
                <el-input v-model="peInfo.stu_nikename"></el-input>
            </el-form-item>
            <el-form-item label="账号:">
                <el-input v-model="peInfo.stu_username"></el-input>
            </el-form-item>
            <el-form-item label="密码:">
                <el-input v-model="peInfo.tea_pwd"></el-input>
            </el-form-item>
            <el-form-item label="班级:">
                <el-input v-model="peInfo.class_name"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-switch v-model="peInfo.stu_state"
                           active-value="0"
                           inactive-value="1"></el-switch>
            </el-form-item>


            <el-form-item>
                <el-button type="primary" @click="addBrand">提交</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>

    </el-dialog>

    </el-dialog>
    <el-container>
        <el-aside width="200px" heigit="100">
            <el-button type="info" @click="findStudent">学生信息管理</el-button>
            <el-button type="info" @click="findTeacher">教师信息管理</el-button>
            <el-button type="info" @click="findAdm">管理员信息管理</el-button>
        </el-aside>
        <el-container>
            <el-header>
                <template>
                    <el-button @click="showAddBrandDialog">新增教师账号</el-button>
                </template>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span>{{this.rightData.adm_username}}</span>
                <el-button type="primary" class="el-icon-switch-button" circle @click="admQuit"></el-button>
            </el-header>
            <el-main>
                <template>
                    <el-table
                            :data="tableData"
                            style="width: 100%"
                            @selection-change="handleSelectionChange"
                            :row-class-name="tableRowClassName">
                        <!---------------------------------多选框属性-------------------------------------------------->
                        <el-table-column
                                align="center"
                                type="selection"
                                width="100">
                        </el-table-column>
                        <!---------------------------------序号属性-------------------------------------------------->
                        <el-table-column
                                label="序号"
                                align="center"
                                type="index"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="stu_nikename"
                                label="姓名(管理员是账号)"
                                width="280"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                prop="class_name"
                                label="所在的班级"
                                width="280"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                label="账号状态"
                                width="300"
                                align="center">
                            <el-switch
                                    v-model="tableData.stu_state"
                                       :active-value="1"
                                       :inactive-value="0">
                                <!-- active-value,  inactive-value,如果要使用number类型,就得在前面加: -->
                            </el-switch>
                        </el-table-column>
                        <!---------------------------------操作按钮------------------------------------->
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope" align="center">
                          <!--      <el-button
                                        type="primary"
                                        size="mini"
                                        @click="handleEdit(scope.row)">编辑
                                </el-button>
                                <br>-->
                                <el-button
                                        size="mini"
                                        type="danger"
                                        @click="handleDelete(scope.row.stu_username)">封禁
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </template>
            </el-main>
        </el-container>
    </el-container>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            tableData: [{
                stu_nikename: '',
                class_name: '',
                stu_state: 0,
                stu_username: '',
            }],
            rightData: {
                adm_username: '',
                adm_password: ''
            },
            /*------------------------------多选框的数据模型----------------------------------*/
            multipleSelection: [],          /*列表数据模型*/
            dialogVisible: false,        /*对话框*/

            /*======================对话框的数据模型=====================*/
            peInfo: {
                stu_nikename: '',
                class_name: '',
                stu_state: '',
                stu_username: '',
                tea_pwd: '',
            },
        },
        methods: {
            findAdm() {
                this.tableData = [];
                var adm_username = this.rightData.adm_username;
                var adm_password = this.rightData.adm_password
                axios.post("/adm/findAdm", {adm_username, adm_password}).then(resp => {
                    console.log(resp);
                    if (resp.data.code == 1) {
                        this.tableData = resp.data.data
                    } else {
                        this.$notify({type: 'error', message: '查询失败！'});
                    }
                })
            },
            /*=============================查找老师的信息=============================*/
            findTeacher() {
                this.tableData = [];
                var adm_username = this.rightData.adm_username;
                var adm_password = this.rightData.adm_password
                axios.post("/adm/findTea", {adm_username, adm_password}).then(resp => {
                    console.log(resp);
                    if (resp.data.code == 1) {
                        this.tableData = resp.data.data
                    } else {
                        this.$notify({type: 'error', message: '查询失败！'});
                    }
                })
            },
            // 点击新增之后触发的点击事件函数
            showAddBrandDialog() {
                // 1.清空数据模型中的数据
                this.peInfo = {};
                // 2.显示对话框
                this.dialogVisible = true;
            },
            // 添加数据
            addBrand() {
                console.log("++++++++++++");
                console.log(this.peInfo);
                console.log("++++++++++++");
                var stu_nikename = this.peInfo.stu_nikename;
                var class_name = this.peInfo.class_name;
                var stu_state = this.peInfo.stu_state;
                var stu_username = this.peInfo.stu_username;
                var tea_pwd = this.peInfo.tea_pwd;
                axios.post("/adm/addTea", {stu_nikename, class_name, stu_state, stu_username, tea_pwd}).then(resp => {
                    console.log(resp);
                    if (resp.data.code == 1) {
                    this.dialogVisible = false
                        this.$notify({type: 'success', message: '成功！'});
                    } else {
                        this.$notify({type: 'error', message: resp.data.msg});
                    }
                })
            },
            /*------------------------------编辑和删除按钮的函数-------(拿到当前表格的元素   1)---------------------------*/
            handleEdit(row) {
                this.tableData = row;
                this.showAddBrandDialog()
                console.log(row);

            },

            /*------------------------------编辑和删除按钮的函数-------(拿到当前表格的元素  2)---------------------------*/
            handleDelete(row) {
                console.log(row);
                var stu_username = row;
                console.log("++++++++++++++++");
                axios.post("/adm/del",{stu_username} ).then(resp => {
                    if(resp.data.code == 1){
                        this.$notify({type: 'success', message: resp.data.data});
                    }else {
                        this.$notify({type: 'error', message: '删出失败'});
                    }
                })
            },
            /*------------------------------多选框的函数----------------------------------*/
            handleSelectionChange(val) {
                console.log(val);
                this.multipleSelection = val;
            },
            /*-----------------------------表格的颜色------------------*/
            tableRowClassName({row, rowIndex}) {
                if (rowIndex % 2 == 1) {
                    return 'warning-row';
                } else if (rowIndex % 2 != 1) {
                    return 'success-row';
                }
                return '';
            }
            ,
            shezhi() {
                this.rightData.adm_username = sessionStorage.getItem("username")
                this.rightData.adm_password = sessionStorage.getItem("pwd")
            }
            ,
            admQuit() {
                sessionStorage.removeItem("username");
                sessionStorage.removeItem("pwd");
                window.requestAnimationFrame(() => {
                    window.location.href = '/index.html'
                })
            }
            ,
            findStudent() {
                var adm_username = this.rightData.adm_username;
                var adm_password = this.rightData.adm_password
                axios.post("/adm/findAll", {adm_username, adm_password}).then(resp => {
                    console.log(resp);
                    if (resp.data.code == 1) {
                        this.tableData = resp.data.data
                    } else {
                        this.$notify({type: 'error', message: '查询失败！'});
                    }
                })
            }
        },
        created() {
            this.shezhi();
            this.findStudent();
        }
    });
</script>
</body>
</html>